package com.saikuo.service.elasticsearch;

import org.elasticsearch.client.Client;
import org.elasticsearch.client.transport.TransportClient;
import org.elasticsearch.common.transport.InetSocketTransportAddress;

import java.net.InetAddress;
import java.net.UnknownHostException;

/**
 * Created by work on 2016/10/25.
 */
public class ElasticsearchFactory {

    private volatile static Client client;

    public static Client getTransportClient() throws UnknownHostException {
        if (client == null) {
            synchronized (ElasticsearchFactory.class) {
                if (client == null) {
                    client = TransportClient.builder()
                            .build()
                            .addTransportAddress(
                                    new InetSocketTransportAddress(
                                            InetAddress.getByName("10.27.17.121"), 9300));
                    return client;
                }
            }
        }
        return client;
    }


}
